package com.lin.cms.service.impl;

import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lin.cms.util.Paging;
import com.lin.cms.criteria.SiteFlowCriteria;
import com.lin.cms.domain.SiteFlow;
import com.lin.cms.service.SiteFlowService;
import com.lin.cms.dao.SiteFlowMapper;

@Service
public class SiteFlowServiceImpl implements SiteFlowService{
	
	public SiteFlow selectByPrimaryKey(Integer flowId){
		return siteFlowMapper.selectByPrimaryKey(flowId);
	}
	
	public List<SiteFlow> selectByCriteria(SiteFlowCriteria criteria){
		return siteFlowMapper.selectByCriteria(criteria);
	}
	
	public int deleteByPrimaryKey(Integer flowId){
		int actualRowsAffected = 0;
		
		SiteFlow _oldSiteFlow = siteFlowMapper.selectByPrimaryKey(flowId);
		
		if (_oldSiteFlow != null) {
			actualRowsAffected = siteFlowMapper.deleteByPrimaryKey(flowId);
		}
		
		return actualRowsAffected;
	}
	
	public int deleteByCriteria(SiteFlowCriteria criteria){
		int actualRowsAffected = 0;
		
		List<SiteFlow> _oldSiteFlow = siteFlowMapper.selectByCriteria(criteria);
		
		if (_oldSiteFlow.size() != 0) {
			actualRowsAffected = siteFlowMapper.deleteByCriteria(criteria);
		}
		
		return actualRowsAffected;
	}
	
	public int insert(SiteFlow siteFlow){
		return siteFlowMapper.insert(siteFlow);
	}
	
	public int updateByPrimaryKeySelective(SiteFlow siteFlow){
		int actualRowsAffected = 0;
		
		int advertisingId = siteFlow.getFlowId();

		SiteFlow _oldSiteFlow = siteFlowMapper.selectByPrimaryKey(advertisingId);
		
		if (_oldSiteFlow != null) {
			actualRowsAffected = siteFlowMapper.updateByPrimaryKeySelective(siteFlow);
		}
		
		return actualRowsAffected;
	}
	
	public int updateByPrimaryKey(SiteFlow siteFlow){
		int actualRowsAffected = 0;
		
		int advertisingId = siteFlow.getFlowId();

		SiteFlow _oldSiteFlow = siteFlowMapper.selectByPrimaryKey(advertisingId);
		
		if (_oldSiteFlow != null) {
			actualRowsAffected = siteFlowMapper.updateByPrimaryKey(siteFlow);
		}
		
		return actualRowsAffected;
	}
	
	public List<SiteFlow> selectByPage(SiteFlowCriteria criteria) {
		int totalResults = siteFlowMapper.countByCriteria(criteria);
		Paging paging = criteria.getPaging();
		paging.setTotalResults(totalResults);
		
		return siteFlowMapper.selectByPage(criteria,new RowBounds(paging.getFirstResult(),paging.getMaxResults()));
	}
	
	public int countByCriteria(SiteFlowCriteria criteria){
		return siteFlowMapper.countByCriteria(criteria);
	}
	
	@Autowired
    private SiteFlowMapper siteFlowMapper;
}
